from myelin.server.nodetype.Events import EventHandler
from myelin.Ns import MYELIN, DC, DCTERMS
from myelin.rdf.Ns import RDF_TYPE
from myelin.rdf.bindery.Model import OBJECT_TYPE_RESOURCE, OBJECT_TYPE_LITERAL

from Document import Document


class Document(Document):
        
    def createStatements(self, context, consumer):
                
        acct = context.account
        action = context.action
        actionType = context.nodeType.actions[action]
        
        consumer(
            (
                u'',
                RDF_TYPE,
                t,
                None,
                u'',
                OBJECT_TYPE_RESOURCE
            ) for t in actionType.classTypes
        )
        
        consumer((
            (
                u'',
                MYELIN + 'action',
                action,
                None,
                u'',
                OBJECT_TYPE_LITERAL
            ), (
                u'',
                DC + 'publisher',
                context.defaults.domain_uri,
                None,
                u'',
                OBJECT_TYPE_RESOURCE
            ), (
                u'',
                DCTERMS + u'created',
                unicode(self.newDateTimeString(
                    context.session.dateTime
                )),
                None,
                u'',
                OBJECT_TYPE_LITERAL
            ), (
                u'',
                DC + u'identifier',
                self.newUri(),
                None,
                u'',
                OBJECT_TYPE_RESOURCE
            ), 
        ))
        
        if acct.isAgent():
            consumer((
                (
                    u'',
                    MYELIN + u'requestor',
                    acct.agentId,
                    None,
                    None,
                    OBJECT_TYPE_RESOURCE
                ),
            ))            
        
        
        return self.getStatements(context, consumer)
    

class EventHandler(EventHandler):
    
    newDocument = Document
